﻿using AuthCenter.Api.Read.Application.Command.RoleMenu;
using AuthCenter.Application;
using AuthCenter.Domain;
using AuthCenter.ErrorCode;
using AutoMapper;
using MediatR;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace AuthCenter.Api.Read.Application.Hander.RoleMenu
{
    public class GetRoleHander : IRequestHandler<GetRoleCommand, ApiResult<List<RoleModel>>>
    {
        private readonly IBaseRepository<RoleModel> _roleRepository;
        private readonly IBaseRepository<RoleMenuModel> _roleMenuRepository;
        private readonly IBaseRepository<MenuModel> _menuRepository;
        private readonly IBaseRepository<UserModel> _userRepository;
        private readonly IBaseRepository<UserRoleModel> _userroleRepository;
        private readonly IMapper _mapper;
        public GetRoleHander(IBaseRepository<RoleModel> roleRepository, IBaseRepository<RoleMenuModel> roleMenuRepository, IMapper mapper, IBaseRepository<MenuModel> menuRepository, IBaseRepository<UserModel> userRepository, IBaseRepository<UserRoleModel> userroleRepository)
        {
            _roleRepository = roleRepository;
            _roleMenuRepository = roleMenuRepository;
            _mapper = mapper;
            _menuRepository = menuRepository;
            _userRepository = userRepository;
            _userroleRepository = userroleRepository;
        }
        /// <summary>
        /// 获取角色
        /// </summary>
        /// <returns></returns>
        public Task<ApiResult<List<RoleModel>>> Handle(GetRoleCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<RoleModel>> res = new ApiResult<List<RoleModel>>();
            var model = _roleRepository.GetAll().Where(x => x.IsDeleted == false);
            res.Code = ApiEnums.OK;
            res.Message = "获取成功";
            res.Data = model.ToList();
            return Task.FromResult(res);
        }
    }
}
